import request from '@/utils/request'

// 查询优惠券组列表
export function listGroup(query) {
  return request({
    url: '/api/group/list',
    method: 'get',
    params: query
  })
}

// 查询优惠券组详细
export function getGroup(id) {
  return request({
    url: '/api/group/' + id,
    method: 'get'
  })
}

// 新增优惠券组
export function addGroup(data) {
  return request({
    url: '/api/group/add',
    method: 'post',
    data: data
  })
}

// 修改优惠券组
export function updateGroup(data) {
  return request({
    url: '/api/group/edit',
    method: 'put',
    data: data
  })
}

// 删除优惠券组
export function delGroup(id) {
  return request({
    url: '/api/group/remove/' + id,
    method: 'delete'
  })
}

// 根据优惠券组ID查询优惠券
export function getCouponsByGroupId(groupId) {
  return request({
    url: '/api/coupons/group/' + groupId,
    method: 'get'
  })
}

// 创建优惠券
export function createCoupon(data) {
  return request({
    url: '/api/coupons/createCoupon',
    method: 'post',
    data: data
  })
}

// 删除优惠券
export function deleteCoupon(id) {
  return request({
    url: '/api/coupons/deleteCoupon/' + id,
    method: 'delete'
  })
}

// 查询优惠券详细
export function getProductCoupon(couponId) {
  return request({
    url: '/api/coupons/' + couponId,
    method: 'get'
  })
}

//为优惠券添加商品
export function addCouponProduct(data, couponId) {
  let params = data
  return request({
    url: `/api/coupons/relate-sku/${couponId}`,
    method: "post",
    data: params
  })
}

//从优惠券中移除商品
export function deleteCouponProduct(couponId) {
  return request({
    url: `/api/coupons/remove-sku-relation/${couponId}`,
    method: "delete"
  })
}
